//
//  StorageService.m
//  CheXunWang
//
//  Created by zhu lin on 12/17/11.
//  Copyright 2011 Zhulin. All rights reserved.
//

#import "StorageService.h"


@implementation StorageService

+ (NSString *) getDocumentStoreUrl
{
	return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
}

+ (void) createDictionaryIfNotExist:(NSString *) path
{
	NSFileManager *filemgr = [NSFileManager defaultManager];
	if (![filemgr fileExistsAtPath:path]) {
		[filemgr createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error: NULL];
	}
}

+ (NSString *)getPathByStorageType:(ZLStorageType)type withFileName:(NSString *)fileName
{
	// Get client Document directory.
    NSString *documentsDirectory = [StorageService getDocumentStoreUrl];
	NSArray *typeDirs = [NSArray arrayWithObjects:@"BrandImages", @"SeriesImages", nil];
	NSString *dirPath = [documentsDirectory stringByAppendingPathComponent:(NSString *)[typeDirs objectAtIndex:type]];
	[StorageService createDictionaryIfNotExist:dirPath];
	return [dirPath stringByAppendingPathComponent:fileName];
}
@end
